home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 November: Tool Chest / Dev.CD Nov 00 TC Disk 2.toast / pc / sample code / quicktime / quicktimeintro / createmovie / common files / comframework.c next >
Encoding:
Text File  |  2000-10-06  |  53.8 KB  |  1,969 lines

  1. //////////
  2. //
  3. //    File:        ComFramework.c
  4. //
  5. //    Contains:    Code for the QuickTime sample code framework that is common to both Macintosh and Windows.
  6. //
  7. //    Written by:    Tim Monroe
  8. //                Based on the QTShell code written by Tim Monroe, which in turn was based on the MovieShell
  9. //                code written by Kent Sandvik (Apple DTS). This current version is now very far removed from
  10. //                MovieShell.
  11. //
  12. //    Copyright:    © 1999 by Apple Computer, Inc., all rights reserved.
  13. //
  14. //    Change History (most recent first):
  15. //       
  16. //       <15>         03/02/00    rtm        made changes to get things running under CarbonLib
  17. //       <14>         02/16/00    rtm        added QTFrame_GetWindowPtrFromWindowReference
  18. //       <13>         01/19/00    rtm        revised QTFrame_IsAppWindow (dialog windows no longer count as application
  19. //                                    windows); added QTFrame_BuildFileTypeList and QTFrame_AddComponentFileTypes
  20. //                                    to avoid calling GetMovieImporterForDataRef in QTFrame_FilterFiles; removed
  21. //                                    the hard-coded file types
  22. //       <12>         01/14/00    rtm        added support for graphics files, using graphics importers
  23. //       <11>         12/28/99    rtm        added QTFrame_ConvertMacToWinRect and QTFrame_ConvertWinToMacRect
  24. //       <10>         12/21/99    rtm        hard-coded some file types into QTFrame_FilterFiles; if we let QuickTime
  25. //                                    to do all the testing (using GetMovieImporterForDataRef), it takes too long
  26. //       <9>         12/17/99    rtm        added some code to QTFrame_SetMenuItemState to work around a problem that
  27. //                                    appears under MacOS 8.5.1 (as far as I can tell...)
  28. //       <8>         12/16/99    rtm        added QTApp_HandleMenu calls to _HandleFileMenuItem and _HandleEditMenuItem
  29. //                                    to allow the application-specific code to intercept menu item selections;
  30. //                                    added QTFrame_FilterFiles
  31. //       <7>         12/15/99    rtm        added QTApp_Idle call to QTFrame_IdleMovieWindows
  32. //       <6>         12/11/99    rtm        added GetMenuState call to Windows portion of QTFrame_SetMenuItemLabel;
  33. //                                    tweaked _SizeWindowToMovie to guard against NULL movie and/or controller
  34. //       <5>         11/30/99    rtm        added QTFrame_CloseMovieWindows
  35. //       <4>         11/27/99    rtm        added QTFrame_GetFileFilterUPP
  36. //       <3>         11/17/99    rtm        finished support for Navigation Services; added QTFrame_IdleMovieWindows
  37. //       <2>         11/16/99    rtm        begun support for Navigation Services
  38. //       <1>         11/05/99    rtm        first file
  39. //
  40. //    This file contains several kinds of functions: (1) functions that use completely cross-platform APIs and
  41. //    which therefore can be compiled and run for both Mac and Windows platforms with no changes whatsoever (a
  42. //    good example of this is QTFrame_SaveAsMovieFile); (2) functions that are substantially the same on both
  43. //    platforms but which require several short platform-dependent #ifdef TARGET_OS_ blocks (a good example of
  44. //    this is QTFrame_AdjustMenus); (3) functions that retrieve data from framework-specific data structures (a
  45. //    good example of this is QTFrame_GetWindowObjectFromWindow); (4) functions that provide a platform-neutral
  46. //    interface to platform-specific operations (a good example of this is QTFrame_Beep). In a nutshell, this
  47. //    file attempts to provide platform-independent services to its callers, typically functions in the files
  48. //    MacFramework.c, WinFramework.c, and ComApplication.c.
  49. //
  50. //    In general, you should not need to modify this file. Your application-specific code should usually be put
  51. //    into the file ComApplication.c.
  52. //
  53. //////////
  54.  
  55. //////////
  56. //
  57. // header files
  58. //
  59. //////////
  60.  
  61. #include "ComFramework.h"
  62. #include "CreateMovie.h"
  63. #include "QTFlatten.h"
  64.  
  65.  
  66. //////////
  67. //
  68. // global variables
  69. //
  70. //////////
  71.  
  72. Rect                    gMCResizeBounds;                        // maximum size for any movie window
  73. OSType                     *gValidFileTypes = NULL;                // the list of file types that our application can open
  74.  
  75. #if TARGET_OS_WIN32
  76. extern HWND                ghWnd;
  77. extern HWND                ghWndMDIClient;
  78. extern BOOL                gWeAreSizingWindow;
  79. #endif
  80.  
  81. #if TARGET_OS_MAC
  82. extern Str255            gAppName;
  83. void                    QTFrame_HandleEvent (EventRecord *theEvent);
  84. #endif
  85.  
  86.  
  87. ///////////////////////////////////////////////////////////////////////////////////////////////////////////
  88. //
  89. // Menu-handling functions.
  90. //
  91. // Use these functions to handle items in the File and Edit menus.
  92. //
  93. ///////////////////////////////////////////////////////////////////////////////////////////////////////////
  94.  
  95. //////////
  96. //
  97. // QTFrame_HandleFileMenuItem
  98. // Handle the specified File menu item.
  99. //
  100. //////////
  101.  
  102. void QTFrame_HandleFileMenuItem (WindowReference theWindow, UInt16 theMenuItem)
  103. {
  104.     // give the application-specific code a chance to intercept the menu item selection
  105.     if (QTApp_HandleMenu(theMenuItem))
  106.         return;
  107.         
  108.     switch (theMenuItem) {
  109.     
  110.         case IDM_FILENEW:
  111.             CreateAMovie();
  112.             //QTFrame_CreateNewMovie();
  113.             break;
  114.  
  115.         case IDM_FILEOPEN:
  116.             QTFrame_OpenMovieInWindow(NULL, NULL);
  117.             break;
  118.  
  119.         case IDM_FILECLOSE:
  120.             QTFrame_DestroyMovieWindow(theWindow);
  121.             break;
  122.  
  123.         case IDM_FILESAVE:
  124.             QTFrame_UpdateMovieFile(theWindow);
  125.             break;
  126.  
  127.         case IDM_FILESAVEAS:
  128.             QTFrame_SaveAsMovieFile(theWindow);
  129.             break;
  130.             
  131.         case IDM_EXIT:
  132.             QTFrame_QuitFramework();
  133.             break;
  134.  
  135.         default:
  136.             break;
  137.     } // switch (theMenuItem)
  138.     
  139. }
  140.  
  141.  
  142. //////////
  143. //
  144. // QTFrame_HandleEditMenuItem
  145. // Perform the specified edit operation on the specified window.
  146. //
  147. //////////
  148.  
  149. void QTFrame_HandleEditMenuItem (WindowReference theWindow, UInt16 theMenuItem)
  150. {
  151.     WindowObject        myWindowObject = NULL;
  152.     MovieController     myMC = NULL;
  153.     Movie                 myEditMovie = NULL;                // the movie created by some editing operations
  154.     
  155.     // give the application-specific code a chance to intercept the menu item selection
  156.     if (QTApp_HandleMenu(theMenuItem))
  157.         return;
  158.     
  159.     myWindowObject = QTFrame_GetWindowObjectFromWindow(theWindow);
  160.     myMC = QTFrame_GetMCFromWindow(theWindow);
  161.     
  162.     // make sure we have a valid movie controller and a valid window object
  163.     if ((myMC == NULL) || (myWindowObject == NULL))
  164.         return;
  165.  
  166.     switch (theMenuItem) {
  167.     
  168.         case IDM_EDITUNDO:
  169.             MCUndo(myMC);
  170.             (**myWindowObject).fIsDirty = true;
  171.             break;
  172.  
  173.         case IDM_EDITCUT:
  174.             myEditMovie = MCCut(myMC);
  175.             (**myWindowObject).fIsDirty = true;
  176.             break;
  177.  
  178.         case IDM_EDITCOPY:
  179.             myEditMovie = MCCopy(myMC);
  180.             break;
  181.  
  182.         case IDM_EDITPASTE:
  183.             MCPaste(myMC, NULL);
  184.             (**myWindowObject).fIsDirty = true;
  185.             break;
  186.  
  187.         case IDM_EDITCLEAR:
  188.             MCClear(myMC);
  189.             (**myWindowObject).fIsDirty = true;
  190.             break;
  191.             
  192.         case IDM_EDITSELECTALL:
  193.             QTUtils_SelectAllMovie(myMC);
  194.             break;
  195.  
  196.         case IDM_EDITSELECTNONE:
  197.             QTUtils_SelectNoneMovie(myMC);
  198.             break;
  199.  
  200.         default:
  201.             break;
  202.     } // switch (theMenuItem)
  203.     
  204.     // place any cut or copied movie segment onto the scrap
  205.     if (myEditMovie != NULL) {
  206.         PutMovieOnScrap(myEditMovie, 0L);
  207.         DisposeMovie(myEditMovie);
  208.     }
  209. }
  210.  
  211.  
  212. //////////
  213. //
  214. // QTFrame_AdjustMenus 
  215. // Adjust the application's menus.
  216. //
  217. // On Windows, the theWindow parameter is a handle to the active MDI *child* window, if any.
  218. // On Mac, the theWindow parameter is a pointer to the frontmost window, if any.
  219. //
  220. //////////
  221.  
  222. int QTFrame_AdjustMenus (WindowReference theWindow, MenuReference theMenu)
  223. {
  224. #if TARGET_OS_MAC
  225. #pragma unused(theMenu)
  226. #endif
  227.  
  228.     WindowObject        myWindowObject = NULL; 
  229.     MovieController     myMC = NULL;
  230.     MenuReference        myMenu = NULL;
  231.     
  232. #if TARGET_OS_WIN32
  233.     myMenu = theMenu;
  234. #endif
  235.  
  236.     if (theWindow != NULL)
  237.         myWindowObject = QTFrame_GetWindowObjectFromWindow(theWindow);
  238.  
  239.     if (myWindowObject != NULL)
  240.         myMC = (**myWindowObject).fController;
  241.  
  242.     //////////
  243.     //
  244.     // configure the Edit menu
  245.     //
  246.     //////////
  247.     
  248. #if TARGET_OS_MAC
  249.     myMenu = GetMenuHandle(kEditMenuResID);
  250. #endif
  251.     if (myMC != NULL) {
  252.         long    myFlags;
  253.         
  254.         MCGetControllerInfo(myMC, &myFlags);
  255.     
  256.         QTFrame_SetMenuItemState(myMenu, IDM_EDITUNDO, myFlags & mcInfoUndoAvailable ? kEnableMenuItem : kDisableMenuItem);
  257.         QTFrame_SetMenuItemState(myMenu, IDM_EDITCUT, myFlags & mcInfoCutAvailable ? kEnableMenuItem : kDisableMenuItem);
  258.         QTFrame_SetMenuItemState(myMenu, IDM_EDITCOPY, myFlags & mcInfoCopyAvailable ? kEnableMenuItem : kDisableMenuItem);
  259.         QTFrame_SetMenuItemState(myMenu, IDM_EDITPASTE, myFlags & mcInfoPasteAvailable ? kEnableMenuItem : kDisableMenuItem);
  260.         QTFrame_SetMenuItemState(myMenu, IDM_EDITCLEAR, myFlags & mcInfoClearAvailable ? kEnableMenuItem : kDisableMenuItem);
  261.         QTFrame_SetMenuItemState(myMenu, IDM_EDITSELECTALL, myFlags & mcInfoEditingEnabled ? kEnableMenuItem : kDisableMenuItem);
  262.         QTFrame_SetMenuItemState(myMenu, IDM_EDITSELECTNONE, myFlags & mcInfoEditingEnabled ? kEnableMenuItem : kDisableMenuItem);
  263.     } else {
  264.         QTFrame_SetMenuItemState(myMenu, IDM_EDITUNDO, kDisableMenuItem);
  265.         QTFrame_SetMenuItemState(myMenu, IDM_EDITCUT, kDisableMenuItem);
  266.         QTFrame_SetMenuItemState(myMenu, IDM_EDITCOPY, kDisableMenuItem);
  267.         QTFrame_SetMenuItemState(myMenu, IDM_EDITPASTE, kDisableMenuItem);
  268.         QTFrame_SetMenuItemState(myMenu, IDM_EDITCLEAR, kDisableMenuItem);
  269.         QTFrame_SetMenuItemState(myMenu, IDM_EDITSELECTALL, kDisableMenuItem);
  270.         QTFrame_SetMenuItemState(myMenu, IDM_EDITSELECTNONE, kDisableMenuItem);
  271.     }
  272.  
  273.     //////////
  274.     //
  275.     // configure the File menu
  276.     //
  277.     //////////
  278.     
  279. #if TARGET_OS_MAC
  280.     myMenu = GetMenuHandle(kFileMenuResID);
  281. #endif
  282.     if (theWindow != NULL) {                // there is a window open
  283.         // handle the Close command
  284.         QTFrame_SetMenuItemState(myMenu, IDM_FILECLOSE, kEnableMenuItem);
  285.         
  286.         // handle the Save As and Save commands
  287.         if (myWindowObject != NULL) {
  288.             QTFrame_SetMenuItemState(myMenu, IDM_FILESAVEAS, kEnableMenuItem);
  289.             QTFrame_SetMenuItemState(myMenu, IDM_FILESAVE, (**myWindowObject).fIsDirty ? kEnableMenuItem : kDisableMenuItem);
  290.         } else {
  291.             QTFrame_SetMenuItemState(myMenu, IDM_FILESAVEAS, kDisableMenuItem);
  292.             QTFrame_SetMenuItemState(myMenu, IDM_FILESAVE, kDisableMenuItem);
  293.         }
  294.     
  295.     } else {                                // there is no window open    
  296.         QTFrame_SetMenuItemState(myMenu, IDM_FILESAVE, kDisableMenuItem);
  297.         QTFrame_SetMenuItemState(myMenu, IDM_FILESAVEAS, kDisableMenuItem);
  298.         QTFrame_SetMenuItemState(myMenu, IDM_FILECLOSE, kDisableMenuItem);        
  299.     }
  300.  
  301.     // adjust any application-specific menus
  302.     QTApp_AdjustMenus(theWindow, theMenu);
  303.  
  304.     return(0);
  305. }
  306.  
  307.  
  308. ///////////////////////////////////////////////////////////////////////////////////////////////////////////
  309. //
  310. // Movie-handling functions.
  311. //
  312. // Use these functions to create new movies, open existing movies, save movies, and so forth.
  313. //
  314. ///////////////////////////////////////////////////////////////////////////////////////////////////////////
  315.  
  316. //////////
  317. //
  318. // QTFrame_CreateNewMovie
  319. // Create a new movie in a window; returns true if successful.
  320. //
  321. // NOTE: There are several user interface issues that are blissfully ignored by this routine,
  322. // principally the preferred names and the on-screen locations of the new windows. 
  323. //
  324. //////////
  325.  
  326. Boolean QTFrame_CreateNewMovie (void)
  327. {
  328.     Movie                myMovie = NULL;
  329.     FSSpec                myFSSpec;
  330.     StringPtr             myName = QTUtils_ConvertCToPascalString(kNewMovieName);
  331.     
  332.     myMovie = NewMovie(newMovieActive);
  333.     if (myMovie == NULL)
  334.         return(false);
  335.     
  336.     // create a default FSSpec
  337.     FSMakeFSSpec(0, 0L, myName, &myFSSpec);
  338.     
  339.     free(myName);
  340.     
  341.     return(QTFrame_OpenMovieInWindow(myMovie, &myFSSpec));
  342. }
  343.  
  344.  
  345. //////////
  346. //
  347. // QTFrame_OpenMovieInWindow
  348. // Open a movie in a new movie window; return true if successful.
  349. //
  350. // This function is called from several places in our framework. The following combinations are possible:
  351. //    * theMovie == NULL, theFSSpec == NULL: no movie, no file; elicit a movie file from user and open it
  352. //    * theMovie != NULL, theFSSpec == NULL: new movie, no file (yet)
  353. //    * theMovie == NULL, theFSSpec != NULL: no movie, but we have an FSSpec; so just open the specified movie file
  354. //    * theMovie != NULL, theFSSpec != NULL: new movie, theFSSpec contains (at least) the movie name
  355. //
  356. //////////
  357.  
  358. Boolean QTFrame_OpenMovieInWindow (Movie theMovie, FSSpec *theFSSpec)
  359. {
  360.     WindowObject            myWindowObject = NULL;
  361.     Movie                    myMovie = NULL;
  362.     MovieController            myMC = NULL;
  363.     GraphicsImportComponent    myImporter = NULL;
  364.     WindowReference            myWindow = NULL;
  365.     FSSpec                    myFSSpec;
  366.     short                    myRefNum = kInvalidFileRefNum;
  367.     short                    myResID = 0;
  368.     OSType                     myTypeList[] = {kQTFileTypeMovie, kQTFileTypeQuickTimeImage};
  369.     short                    myNumTypes = 2;
  370.     GrafPtr                    mySavedPort;
  371.     Rect                    myRect = {0, 0, 0, 0};
  372.     Point                    myPoint;
  373.     QTFrameFileFilterUPP    myFileFilterUPP = NULL;
  374.     OSErr                    myErr = noErr;
  375.  
  376. #if TARGET_OS_MAC
  377.     myNumTypes = 0;
  378. #endif
  379.  
  380.     // get the current port; we may need to restore it if we cannot successfully create a new window
  381.     GetPort(&mySavedPort);
  382.     
  383.     // if we got neither a movie nor an FSSpec passed in, prompt the user for a movie file
  384.     if ((theMovie == NULL) && (theFSSpec == NULL)) {
  385.         myFileFilterUPP = QTFrame_GetFileFilterUPP((ProcPtr)QTFrame_FilterFiles);
  386.     
  387.         myErr = QTFrame_GetOneFileWithPreview(myNumTypes, (QTFrameTypeListPtr)myTypeList, &myFSSpec, myFileFilterUPP);
  388.     
  389.         if (myFileFilterUPP != NULL)
  390.             DisposeNavObjectFilterUPP(myFileFilterUPP);
  391.  
  392.         if (myErr != noErr)
  393.             goto bail;
  394.     }
  395.     
  396.     // if we got an FSSpec passed in, copy it into myFSSpec
  397.     if (theFSSpec != NULL) {
  398.         FSMakeFSSpec(theFSSpec->vRefNum, theFSSpec->parID, theFSSpec->name, &myFSSpec);        
  399.     }
  400.  
  401.     // if we got no movie passed in, read one from the specified file
  402.     if (theMovie == NULL) {
  403.  
  404.         // see if the FSSpec picks out an image file; if so, skip the movie-opening code
  405.         // NOTE: The next 3 lines were commented out to get this working on OS X DP3
  406.         myErr = GetGraphicsImporterForFile(&myFSSpec, &myImporter);
  407.         if (myImporter != NULL)
  408.             goto gotImageFile;
  409.             
  410.         // ideally, we'd like read and write permission, but we'll settle for read-only permission
  411.         myErr = OpenMovieFile(&myFSSpec, &myRefNum, fsRdWrPerm);
  412.         if (myErr != noErr)
  413.             myErr = OpenMovieFile(&myFSSpec, &myRefNum, fsRdPerm);
  414.  
  415.         // if we couldn't open the file with even just read-only permission, bail....
  416.         if (myErr != noErr)
  417.             goto bail;
  418.  
  419.         // now fetch the first movie from the file
  420.         myResID = 0;
  421.         myErr = NewMovieFromFile(&myMovie, myRefNum, &myResID, NULL, newMovieActive, NULL);
  422.         if (myErr != noErr)
  423.             goto bail;
  424.     } else {
  425.         myMovie = theMovie;
  426.     }
  427.  
  428.     //////////
  429.     //
  430.     // at this point, myMovie is an open movie, but myFSSpec may or may not be a valid FSSpec
  431.     //
  432.     //////////
  433.     
  434.     // set the default progress procedure for the movie
  435.     SetMovieProgressProc(myMovie, (MovieProgressUPP)-1, 0);
  436.         
  437. gotImageFile:
  438.     // create a new window to display the movie in
  439.     myWindow = QTFrame_CreateMovieWindow();
  440.     if (myWindow == NULL)
  441.         goto bail;
  442.     
  443.     myWindowObject = QTFrame_GetWindowObjectFromWindow(myWindow);
  444.     if (myWindowObject == NULL)
  445.         goto bail;
  446.     
  447.     // set the window title
  448.     QTFrame_SetWindowTitleFromFSSpec(myWindow, &myFSSpec, true);
  449.  
  450.     // make sure the movie or image file uses the window GWorld
  451.     if (myMovie != NULL)
  452.         SetMovieGWorld(myMovie, (CGrafPtr)QTFrame_GetPortFromWindowReference(myWindow), NULL);
  453.  
  454.     if (myImporter != NULL)
  455.         GraphicsImportSetGWorld(myImporter, (CGrafPtr)QTFrame_GetPortFromWindowReference(myWindow), NULL);
  456.  
  457.     // create and configure the movie controller
  458.     myMC = QTFrame_SetupController(myMovie, myWindow, true);
  459.         
  460.     // store movie info in the window record
  461.     (**myWindowObject).fMovie = myMovie;
  462.     (**myWindowObject).fController = myMC;
  463.     (**myWindowObject).fGraphicsImporter = myImporter;
  464.     (**myWindowObject).fFileResID = myResID;
  465.     (**myWindowObject).fFileRefNum = myRefNum;
  466.     (**myWindowObject).fCanResizeWindow = true;
  467.     (**myWindowObject).fIsDirty = false;
  468.     (**myWindowObject).fIsQTVRMovie = QTUtils_IsQTVRMovie(myMovie);
  469.     (**myWindowObject).fInstance = NULL;
  470.     (**myWindowObject).fAppData = NULL;
  471.     (**myWindowObject).fFileFSSpec = myFSSpec;
  472.     
  473.     // do any application-specific window object initialization
  474.     QTApp_SetupWindowObject(myWindowObject);
  475.     
  476.     // size the window to fit the movie and controller
  477.     QTFrame_SizeWindowToMovie(myWindowObject);
  478.  
  479.     // set the movie's play hints to allow dynamic resizing
  480.     SetMoviePlayHints(myMovie, hintsAllowDynamicResize, hintsAllowDynamicResize);
  481.  
  482.     // set the movie's position, if it has a 'WLOC' user data atom
  483.     myErr = QTUtils_GetWindowPositionFromFile(myMovie, &myPoint);
  484.  
  485.     // show the window
  486. #if TARGET_OS_MAC
  487.     MoveWindow(myWindow, myPoint.h, myPoint.v, false);
  488.     ShowWindow(myWindow);
  489.     SelectWindow(myWindow);                                // make it front-most, since it's just been created
  490.     InvalWindowRect(myWindow, GetWindowPortBounds(myWindow, &myRect));
  491. #endif
  492. #if TARGET_OS_WIN32
  493.     SetWindowPos(myWindow, 0, myPoint.h, myPoint.v, 0, 0, SWP_NOZORDER | SWP_NOSIZE);
  494.     ShowWindow(myWindow, SW_SHOW);
  495.     UpdateWindow(myWindow);
  496. #endif
  497.  
  498.     // if the movie is a streamed movie, then start it playing immediately
  499.     if (QTUtils_IsStreamedMovie(myMovie))
  500.         MCDoAction(myMC, mcActionPrerollAndPlay, (void *)GetMoviePreferredRate(myMovie));
  501.         
  502.     return(true);
  503.     
  504. bail:
  505.     if (myWindow != NULL)
  506. #if TARGET_OS_MAC
  507.         DisposeWindow(myWindow);
  508. #endif
  509. #if TARGET_OS_WIN32
  510.         SendMessage(ghWndMDIClient, WM_MDIDESTROY, (WPARAM)myWindow, 0L);
  511. #endif
  512.         
  513.     if (myMC != NULL)
  514.         DisposeMovieController(myMC);
  515.         
  516.     if (myMovie != NULL)
  517.         DisposeMovie(myMovie);
  518.         
  519.     if (myRefNum != 0)
  520.         CloseMovieFile(myRefNum);
  521.  
  522.     if (myImporter != NULL)
  523.         CloseComponent(myImporter);
  524.         
  525.     MacSetPort(mySavedPort);    // restore the port that was active when this function was called
  526.  
  527.     return(false);
  528. }
  529.  
  530.  
  531. //////////
  532. //
  533. // QTFrame_SetupController
  534. // Create and configure the movie controller.
  535. //
  536. //////////
  537.  
  538. MovieController QTFrame_SetupController (Movie theMovie, WindowReference theWindow, Boolean theMoveWindow)
  539. {
  540. #if TARGET_OS_WIN32
  541. #pragma unused(theMoveWindow)
  542. #endif
  543.  
  544.     MovieController            myMC = NULL;
  545.     Rect                    myRect;
  546.     WindowObject            myWindowObject = NULL;
  547.     GrafPtr                    mySavedPort;
  548.  
  549.     if ((theMovie == NULL) || (theWindow == NULL))
  550.         return(NULL);
  551.         
  552.     // get our window specific data
  553.     myWindowObject = QTFrame_GetWindowObjectFromWindow(theWindow);
  554.     if (myWindowObject == NULL)
  555.         return(NULL);
  556.         
  557.     GetPort(&mySavedPort);
  558.     MacSetPort(QTFrame_GetPortFromWindowReference(theWindow));
  559.     
  560.     // resize the movie bounding rect and offset to 0,0
  561.     GetMovieBox(theMovie, &myRect);
  562.     MacOffsetRect(&myRect, -myRect.left, -myRect.top);
  563.     SetMovieBox(theMovie, &myRect);
  564.     AlignWindow(QTFrame_GetWindowFromWindowReference(theWindow), false, &myRect, NULL);
  565.  
  566.     // create the movie controller
  567.     myMC = NewMovieController(theMovie, &myRect, mcTopLeftMovie);
  568.     if (myMC == NULL)
  569.         return(NULL);
  570.         
  571.     // enable the default movie controller editing
  572.     MCEnableEditing(myMC, true);
  573.         
  574.     // suppress movie badge
  575.     MCDoAction(myMC, mcActionSetUseBadge, (void *)false);
  576.  
  577.     // set the initial looping state of the movie
  578.     QTUtils_SetLoopingStateFromFile(theMovie, myMC);
  579.     
  580.     // install an action filter that does any application-specific movie controller action processing
  581.     MCSetActionFilterWithRefCon(myMC, NewMCActionFilterWithRefConProc(QTApp_MCActionFilterProc), (long)myWindowObject);
  582.  
  583.     // add grow box for the movie controller
  584.     if ((**myWindowObject).fCanResizeWindow) {
  585. #if TARGET_OS_WIN32
  586.         RECT                myRect;
  587.  
  588.         GetWindowRect(GetDesktopWindow(), &myRect);
  589.         OffsetRect(&myRect, -myRect.left, -myRect.top);
  590.         QTFrame_ConvertWinToMacRect(&myRect, &gMCResizeBounds);
  591. #endif
  592. #if TARGET_OS_MAC
  593.         GetRegionBounds(GetGrayRgn(), &gMCResizeBounds);
  594. #endif
  595.  
  596.         MCDoAction(myMC, mcActionSetGrowBoxBounds, &gMCResizeBounds);
  597.     }
  598.     
  599. #if TARGET_OS_MAC
  600.     if (theMoveWindow)
  601.         MoveWindow(theWindow, kDefaultWindowX, kDefaultWindowY, false);
  602. #endif
  603.  
  604.     MacSetPort(mySavedPort);
  605.  
  606.     // add any application-specific controller functionality
  607.     QTApp_SetupController(myMC);
  608.         
  609.     return(myMC);
  610. }
  611.  
  612.  
  613. //////////
  614. //
  615. // QTFrame_SaveAsMovieFile
  616. // Save the movie in the specified window under a new name.
  617. //
  618. // Human interface guidelines for "Save As..." dictate that, if the user selects a new file name
  619. // for the current movie, then that new file shall become the active one. This means that we need
  620. // to close the current movie file and open the new one.
  621. //
  622. //////////
  623.  
  624. OSErr QTFrame_SaveAsMovieFile (WindowReference theWindow)
  625. {
  626.     WindowObject        myWindowObject = NULL;
  627.     Movie                 myMovie = NULL;
  628.     FSSpec                myFile;
  629.     Boolean                myIsSelected = false;
  630.     Boolean                myIsReplacing = false;    
  631.     StringPtr             myPrompt = QTUtils_ConvertCToPascalString(kSavePrompt);
  632.     StringPtr             myFileName = QTUtils_ConvertCToPascalString(kSaveMovieFileName);
  633.     OSErr                myErr = paramErr;
  634.     
  635.     // get the window object associated with the specified window
  636.     myWindowObject = QTFrame_GetWindowObjectFromWindow(theWindow);
  637.     if (myWindowObject == NULL)
  638.         goto bail;
  639.         
  640.     myMovie = (**myWindowObject).fMovie;
  641.     if (myMovie == NULL)
  642.         goto bail;
  643.     
  644.     QTFrame_PutFile(myPrompt, myFileName, &myFile, &myIsSelected, &myIsReplacing);
  645.     if (myIsSelected) {
  646.         Movie            myNewMovie = NULL;
  647.         MovieController    myMC = NULL;
  648.         //long            myFlags;
  649.         short            myRefNum = kInvalidFileRefNum;
  650.         short            myResID = movieInDataForkResID;
  651.         
  652.         //////////
  653.         //
  654.         // we have a valid FSSpec for the new movie file; now we want to create a new movie file,
  655.         // save the movie data into the new file, close the existing movie file, and then swap
  656.         // the window object data
  657.         //
  658.         //////////
  659.         
  660.         // delete any existing file of that name
  661.         /*if (myIsReplacing) {
  662.             myErr = DeleteMovieFile(&myFile);
  663.             if (myErr != noErr)
  664.                 goto bail;
  665.         }
  666.         
  667.         myFlags = createMovieFileDeleteCurFile | createMovieFileDontOpenFile | createMovieFileDontCreateMovie | createMovieFileDontCreateResFile;
  668.         myErr = CreateMovieFile(&myFile, sigMoviePlayer, smSystemScript, myFlags, NULL, NULL);
  669.         if (myErr != noErr)
  670.             goto bail;
  671.         
  672.         myErr = OpenMovieFile(&myFile, &myRefNum, fsRdWrPerm);
  673.         if (myErr != noErr)
  674.             goto bail;
  675.         */    
  676.         // write existing movie's data into new movie file
  677.         myErr = QTSave_FlattenMovie(myMovie, &myFile);
  678.         //myErr = AddMovieResource(myMovie, myRefNum, &myResID, myFile.name);
  679.         if (myErr != noErr)
  680.             goto bail;
  681.             
  682.                 myErr = OpenMovieFile(&myFile, &myRefNum, fsRdWrPerm);
  683.         if (myErr != noErr)
  684.             goto bail;
  685.  
  686.         // get the new movie from the file
  687.         myErr = NewMovieFromFile(&myNewMovie, myRefNum, &myResID, NULL, newMovieActive, NULL);        
  688.         if (myErr != noErr)
  689.             goto bail;
  690.         
  691.         // create a new movie controller
  692.         myMC = QTFrame_SetupController(myNewMovie, theWindow, false);
  693.         
  694.         //////////
  695.         //
  696.         // if we got to here, we've successfully created a new movie file, and NewMovieFromFile has
  697.         // returned the new movie to us; so we need to close down the current movie and install the
  698.         // new movie in its place
  699.         //
  700.         //////////
  701.         
  702.         // close the existing movie file
  703.         if ((**myWindowObject).fFileRefNum != kInvalidFileRefNum)
  704.             CloseMovieFile((**myWindowObject).fFileRefNum);
  705.         
  706.         // dispose of the existing movie controller and movie resource
  707.         DisposeMovieController((**myWindowObject).fController);
  708.         DisposeMovie(myMovie);
  709.         
  710.         // keep track of the new info
  711.         (**myWindowObject).fMovie = myNewMovie;
  712.         (**myWindowObject).fController = myMC;
  713.         (**myWindowObject).fFileFSSpec = myFile;
  714.         (**myWindowObject).fFileResID = myResID;
  715.         (**myWindowObject).fFileRefNum = myRefNum;
  716.         (**myWindowObject).fIsDirty = false;
  717.  
  718.         // make sure the movie uses the window GWorld in all situations
  719.         SetMovieGWorld(myNewMovie, (CGrafPtr)QTFrame_GetPortFromWindowReference((**myWindowObject).fWindow), NULL);
  720.  
  721.         // set the window title
  722.         QTFrame_SetWindowTitleFromFSSpec(theWindow, &myFile, true);
  723.     } else {
  724.         myErr = userCanceledErr;
  725.     }
  726.     
  727. bail:
  728.     free(myPrompt);
  729.     free(myFileName);
  730.     
  731.     return(myErr);
  732. }
  733.  
  734.  
  735. //////////
  736. //
  737. // QTFrame_UpdateMovieFile
  738. // Update the file (if any) attached to the movie.
  739. //
  740. //////////
  741.  
  742. Boolean QTFrame_UpdateMovieFile (WindowReference theWindow)
  743. {
  744.     WindowObject        myWindowObject = NULL;
  745.     Movie                 myMovie = NULL;
  746.     OSErr                myErr = noErr;
  747.     
  748.     // get the window object associated with the specified window
  749.     myWindowObject = QTFrame_GetWindowObjectFromWindow(theWindow);
  750.     if (myWindowObject == NULL)
  751.         return(false);
  752.         
  753.     myMovie = (**myWindowObject).fMovie;
  754.     if (myMovie == NULL)
  755.         return(false);
  756.     
  757.     // update the current volume setting
  758.     QTUtils_UpdateMovieVolumeSetting(myMovie);
  759.     
  760.     if ((**myWindowObject).fFileRefNum == kInvalidFileRefNum)        // brand new movie, so no file attached to it
  761.         myErr = QTFrame_SaveAsMovieFile(theWindow);
  762.     else                                                            // we have an existing file; just update the movie resource
  763.         myErr = UpdateMovieResource(myMovie, (**myWindowObject).fFileRefNum, (**myWindowObject).fFileResID, NULL);
  764.     
  765.     (**myWindowObject).fIsDirty = false;
  766.  
  767.     return(myErr == noErr);
  768. }
  769.  
  770.  
  771. //////////
  772. //
  773. // QTFrame_IdleMovieWindows
  774. // Do idle-time processing on all open movie windows.
  775. //
  776. //////////
  777.  
  778. void QTFrame_IdleMovieWindows (void)
  779. {    
  780.     WindowReference            myWindow = NULL;
  781.     MovieController            myMC = NULL;
  782.     
  783.     myWindow = QTFrame_GetFrontMovieWindow();
  784.     while (myWindow != NULL) {
  785.         myMC = QTFrame_GetMCFromWindow(myWindow);
  786.         if (myMC != NULL)
  787.             MCIdle(myMC);
  788.             
  789.         QTApp_Idle(myWindow);
  790.         
  791.         myWindow = QTFrame_GetNextMovieWindow(myWindow);
  792.     }
  793. }
  794.  
  795.  
  796. //////////
  797. //
  798. // QTFrame_CloseMovieWindows
  799. // Close all open movie windows.
  800. //
  801. //////////
  802.  
  803. void QTFrame_CloseMovieWindows (void)
  804. {
  805. #if TARGET_OS_MAC    
  806.     WindowReference            myWindow = NULL;
  807.     WindowReference            myNextWindow = NULL;
  808.  
  809.     myWindow = QTFrame_GetFrontMovieWindow();
  810.     while (myWindow != NULL) {
  811.         myNextWindow = QTFrame_GetNextMovieWindow(myWindow);
  812.         QTFrame_DestroyMovieWindow(myWindow);
  813.         myWindow = myNextWindow;
  814.     }
  815. #endif
  816. #if TARGET_OS_WIN32
  817.     SendMessage(ghWnd, WM_COMMAND, (WPARAM)IDM_WINDOWCLOSEALL, 0L);
  818. #endif
  819. }
  820.  
  821.  
  822. //////////
  823. //
  824. // QTFrame_CreateWindowObject
  825. // Create a new window object associated with the specified window.
  826. //
  827. //////////
  828.  
  829. void QTFrame_CreateWindowObject (WindowReference theWindow)
  830. {
  831.     WindowObject            myWindowObject = NULL;
  832.  
  833.     if (theWindow == NULL)
  834.         return;
  835.         
  836.     // allocate space for a window object record and fill in some of its fields
  837.     myWindowObject = (WindowObject)NewHandleClear(sizeof(WindowObjectRecord));
  838.     if (myWindowObject != NULL) {
  839.         (**myWindowObject).fWindow = theWindow;
  840.         (**myWindowObject).fController = NULL;
  841.         (**myWindowObject).fObjectType = kApplicationSignature;
  842.         (**myWindowObject).fCanResizeWindow = true;
  843.         (**myWindowObject).fInstance = NULL;
  844.         (**myWindowObject).fIsDirty = false;
  845.         (**myWindowObject).fAppData = NULL;
  846.     }
  847.     
  848.     // associate myWindowObject (which may be NULL) with the window
  849. #if TARGET_OS_MAC
  850.     SetWRefCon(theWindow, (long)myWindowObject);
  851. #endif
  852. #if TARGET_OS_WIN32
  853.     SetWindowLong(theWindow, GWL_USERDATA, (LPARAM)myWindowObject);
  854.     
  855.     // associate a GrafPort with this window 
  856.     CreatePortAssociation(theWindow, NULL, 0L);
  857. #endif
  858.     
  859.     // set the current port to the new window
  860.     MacSetPort(QTFrame_GetPortFromWindowReference(theWindow));
  861. }
  862.  
  863.  
  864. //////////
  865. //
  866. // QTFrame_CloseWindowObject
  867. // Close a window object and any associated data.
  868. //
  869. //////////
  870.  
  871. void QTFrame_CloseWindowObject (WindowObject theWindowObject)
  872. {
  873.     if (theWindowObject == NULL)
  874.         return;
  875.         
  876.     // close the movie file
  877.     if ((**theWindowObject).fFileRefNum != kInvalidFileRefNum) {
  878.         CloseMovieFile((**theWindowObject).fFileRefNum);
  879.         (**theWindowObject).fFileRefNum = kInvalidFileRefNum;
  880.     }
  881.     
  882.     // dispose movie controller and movie 
  883.     if ((**theWindowObject).fController != NULL) {
  884.         MCSetActionFilterWithRefCon((**theWindowObject).fController, NULL, 0L);
  885.         DisposeMovieController((**theWindowObject).fController);
  886.         (**theWindowObject).fController = NULL;
  887.     }
  888.     
  889.     if ((**theWindowObject).fMovie != NULL) {
  890.         DisposeMovie((**theWindowObject).fMovie);
  891.         (**theWindowObject).fMovie = NULL;
  892.     }
  893.     
  894.     // close the graphics importer, if any
  895.     if ((**theWindowObject).fGraphicsImporter != NULL) {
  896.         CloseComponent((**theWindowObject).fGraphicsImporter);
  897.         (**theWindowObject).fGraphicsImporter = NULL;
  898.     }
  899.     
  900.     // do any application-specific window clean-up
  901.     QTApp_RemoveWindowObject(theWindowObject);
  902.     
  903.     DisposeHandle((Handle)theWindowObject);
  904. }
  905.  
  906.  
  907. ///////////////////////////////////////////////////////////////////////////////////////////////////////////
  908. //
  909. // Window-walking utilities.
  910. //
  911. // Use these functions to iterate through all windows or movie windows belonging to the application.
  912. //
  913. ///////////////////////////////////////////////////////////////////////////////////////////////////////////
  914.  
  915. //////////
  916. //
  917. // QTFrame_GetFrontAppWindow
  918. // Return a reference to the frontmost application window (whether or not it's a movie window).
  919. //
  920. //////////
  921.  
  922. WindowReference QTFrame_GetFrontAppWindow (void)
  923. {
  924. #if TARGET_OS_MAC
  925.     return(FrontWindow());
  926. #endif
  927. #if TARGET_OS_WIN32
  928.     return(GetWindow(ghWnd, GW_HWNDFIRST));
  929. #endif
  930. }
  931.  
  932.  
  933. //////////
  934. //
  935. // QTFrame_GetNextAppWindow
  936. // Return a reference to the next application window (whether or not it's a movie window).
  937. //
  938. //////////
  939.  
  940. WindowReference QTFrame_GetNextAppWindow (WindowReference theWindow)
  941. {
  942. #if TARGET_OS_MAC
  943.     return(theWindow == NULL ? NULL : GetNextWindow(theWindow));
  944. #endif
  945. #if TARGET_OS_WIN32
  946.     return(GetWindow(theWindow, GW_HWNDNEXT));
  947. #endif
  948. }
  949.  
  950.  
  951. //////////
  952. //
  953. // QTFrame_GetFrontMovieWindow
  954. // Return a reference to the frontmost movie window.
  955. //
  956. //////////
  957.  
  958. WindowReference QTFrame_GetFrontMovieWindow (void)
  959. {
  960.     WindowReference            myWindow;
  961.  
  962. #if TARGET_OS_MAC
  963.     myWindow = QTFrame_GetFrontAppWindow();
  964.     while ((myWindow != NULL) && (QTFrame_GetWindowObjectFromWindow(myWindow) == NULL))
  965.         myWindow = QTFrame_GetNextAppWindow(myWindow);
  966. #endif
  967.  
  968. #if TARGET_OS_WIN32
  969.     myWindow = (HWND)SendMessage(ghWndMDIClient, WM_MDIGETACTIVE, 0, 0L);
  970. #endif
  971.  
  972.     return(myWindow);
  973. }
  974.  
  975.  
  976. //////////
  977. //
  978. // QTFrame_GetNextMovieWindow
  979. // Return a reference to the next movie window.
  980. //
  981. //////////
  982.  
  983. WindowReference QTFrame_GetNextMovieWindow (WindowReference theWindow)
  984. {
  985.     WindowReference            myWindow;
  986.  
  987. #if TARGET_OS_MAC
  988.     myWindow = QTFrame_GetNextAppWindow(theWindow);
  989.     while ((myWindow != NULL) && (QTFrame_GetWindowObjectFromWindow(myWindow) == NULL))
  990.         myWindow = QTFrame_GetNextAppWindow(myWindow);
  991. #endif
  992.  
  993. #if TARGET_OS_WIN32
  994.     myWindow = GetWindow(theWindow, GW_HWNDNEXT);
  995. #endif
  996.  
  997.     return(myWindow);
  998. }
  999.  
  1000.  
  1001. ///////////////////////////////////////////////////////////////////////////////////////////////////////////
  1002. //
  1003. // Data-retrieval utilities.
  1004. //
  1005. // Use the following functions to retrieve the window object, the application-specific data, or the movie
  1006. // controller that is associated with a window.
  1007. //
  1008. ///////////////////////////////////////////////////////////////////////////////////////////////////////////
  1009.  
  1010. //////////
  1011. //
  1012. // QTFrame_GetWindowObjectFromFrontWindow
  1013. // Get the window object (if any) associated with the front window.
  1014. //
  1015. //////////
  1016.  
  1017. WindowObject QTFrame_GetWindowObjectFromFrontWindow (void)
  1018. {
  1019.     return(QTFrame_GetWindowObjectFromWindow(QTFrame_GetFrontMovieWindow()));
  1020. }
  1021.  
  1022.  
  1023. //////////
  1024. //
  1025. // QTFrame_GetWindowObjectFromWindow
  1026. // Get the window object (if any) associated with the specified window.
  1027. //
  1028. //////////
  1029.  
  1030. WindowObject QTFrame_GetWindowObjectFromWindow (WindowReference theWindow)
  1031. {
  1032.     WindowObject        myWindowObject = NULL;
  1033.  
  1034.     if (!QTFrame_IsAppWindow(theWindow))
  1035.         return(NULL);
  1036.             
  1037. #if TARGET_OS_MAC
  1038.     myWindowObject = (WindowObject)GetWRefCon(theWindow);
  1039. #endif
  1040. #if TARGET_OS_WIN32
  1041.     myWindowObject = (WindowObject)GetWindowLong(theWindow, GWL_USERDATA);
  1042. #endif
  1043.  
  1044.     // make sure this is a window object
  1045.     if (!QTFrame_IsWindowObjectOurs(myWindowObject))
  1046.         return(NULL);
  1047.         
  1048.     return(myWindowObject);
  1049. }
  1050.  
  1051.  
  1052. //////////
  1053. //
  1054. // QTFrame_GetMCFromFrontWindow
  1055. // Get the movie controller (if any) associated with the front window.
  1056. //
  1057. //////////
  1058.  
  1059. MovieController QTFrame_GetMCFromFrontWindow (void)
  1060. {
  1061.     return(QTFrame_GetMCFromWindow(QTFrame_GetFrontMovieWindow()));
  1062. }
  1063.  
  1064.  
  1065. //////////
  1066. //
  1067. // QTFrame_GetMCFromWindow
  1068. // Get the movie controller (if any) associated with the specified window.
  1069. //
  1070. //////////
  1071.  
  1072. MovieController QTFrame_GetMCFromWindow (WindowReference theWindow)
  1073. {
  1074.     MovieController     myMC = NULL;
  1075.     WindowObject        myWindowObject = NULL;
  1076.         
  1077.     myWindowObject = QTFrame_GetWindowObjectFromWindow(theWindow);
  1078.     if (myWindowObject != NULL)
  1079.         myMC = (**myWindowObject).fController;
  1080.         
  1081.     return(myMC);
  1082. }
  1083.  
  1084.  
  1085. //////////
  1086. //
  1087. // QTFrame_GetQTVRInstanceFromFrontWindow
  1088. // Get the QTVRInstance (if any) associated with the front window.
  1089. //
  1090. //////////
  1091.  
  1092. QTVRInstance QTFrame_GetQTVRInstanceFromFrontWindow (void)
  1093. {
  1094.     return(QTFrame_GetQTVRInstanceFromWindow(QTFrame_GetFrontMovieWindow()));
  1095. }
  1096.  
  1097.  
  1098. //////////
  1099. //
  1100. // QTFrame_GetQTVRInstanceFromWindow
  1101. // Get the QTVRInstance (if any) associated with the specified window.
  1102. //
  1103. //////////
  1104.  
  1105. QTVRInstance QTFrame_GetQTVRInstanceFromWindow (WindowReference theWindow)
  1106. {
  1107.     QTVRInstance         myInstance = NULL;
  1108.     WindowObject        myWindowObject = NULL;
  1109.     
  1110.     myWindowObject = QTFrame_GetWindowObjectFromWindow(theWindow);
  1111.     if (myWindowObject != NULL)
  1112.         myInstance = (**myWindowObject).fInstance;
  1113.         
  1114.     return(myInstance);
  1115. }
  1116.  
  1117.  
  1118. //////////
  1119. //
  1120. // QTFrame_GetAppDataFromFrontWindow
  1121. // Get the application-specific data associated with the front window.
  1122. //
  1123. //////////
  1124.  
  1125. Handle QTFrame_GetAppDataFromFrontWindow (void)
  1126. {
  1127.     return(QTFrame_GetAppDataFromWindow(QTFrame_GetFrontMovieWindow()));
  1128. }
  1129.  
  1130.  
  1131. //////////
  1132. //
  1133. // QTFrame_GetAppDataFromWindow
  1134. // Get the application-specific data associated with the specified window.
  1135. //
  1136. //////////
  1137.  
  1138. Handle QTFrame_GetAppDataFromWindow (WindowReference theWindow)
  1139. {
  1140.     WindowObject        myWindowObject = NULL;
  1141.     
  1142.     myWindowObject = QTFrame_GetWindowObjectFromWindow(theWindow);
  1143.     if (myWindowObject == NULL)
  1144.         return(NULL);
  1145.         
  1146.     return(QTFrame_GetAppDataFromWindowObject(myWindowObject));
  1147. }
  1148.  
  1149.  
  1150. //////////
  1151. //
  1152. // QTFrame_GetAppDataFromWindowObject
  1153. // Get the application-specific data associated with the specified window object.
  1154. //
  1155. //////////
  1156.  
  1157. Handle QTFrame_GetAppDataFromWindowObject (WindowObject theWindowObject)
  1158. {
  1159.     // make sure this is a window object belonging to our application
  1160.     if (!QTFrame_IsWindowObjectOurs(theWindowObject))
  1161.         return(NULL);
  1162.     
  1163.     return((**theWindowObject).fAppData);
  1164. }
  1165.  
  1166.  
  1167. //////////
  1168. //
  1169. // QTFrame_IsWindowObjectOurs
  1170. // Does the specified window object belong to our application?
  1171. //
  1172. //////////
  1173.  
  1174. Boolean QTFrame_IsWindowObjectOurs (WindowObject theWindowObject)
  1175. {
  1176.     OSType        myType = 0L;
  1177.  
  1178.     if ((theWindowObject == NULL) || (*theWindowObject == NULL))
  1179.         return(false);
  1180.         
  1181.     myType = (**theWindowObject).fObjectType;
  1182.     return(myType == kApplicationSignature);
  1183. }
  1184.  
  1185.  
  1186. //////////
  1187. //
  1188. // QTFrame_IsAppWindow
  1189. // Does the specified window belong to our application?
  1190. //
  1191. //////////
  1192.  
  1193. Boolean QTFrame_IsAppWindow (WindowReference theWindow)
  1194. {
  1195.     if (theWindow == NULL)
  1196.         return(false);
  1197.  
  1198. #if TARGET_OS_MAC
  1199.     return(GetWindowKind(theWindow) >= kApplicationWindowKind);
  1200. #endif
  1201. #if TARGET_OS_WIN32
  1202.     return(true);
  1203. #endif
  1204. }
  1205.  
  1206.  
  1207. //////////
  1208. //
  1209. // QTFrame_IsDocWindow
  1210. // Is the specified window a document window (having a WindowObject refcon)?
  1211. //
  1212. //////////
  1213.  
  1214. Boolean QTFrame_IsDocWindow (WindowReference theWindow)
  1215. {
  1216.     if (theWindow == NULL)
  1217.         return(false);
  1218.  
  1219. #if TARGET_OS_MAC
  1220.     return(GetWindowKind(theWindow) >= kApplicationWindowKind);
  1221. #endif
  1222. #if TARGET_OS_WIN32
  1223.     return(true);
  1224. #endif
  1225. }
  1226.  
  1227.  
  1228. //////////
  1229. //
  1230. // QTFrame_ActivateController
  1231. // Activate or deactivate the movie controller in the specified window.
  1232. //
  1233. //////////
  1234.  
  1235. void QTFrame_ActivateController (WindowReference theWindow, Boolean IsActive)
  1236. {
  1237.     WindowObject         myWindowObject = NULL;
  1238.     MovieController        myMC = NULL;
  1239.     GrafPtr                mySavedPort = NULL;
  1240.     
  1241.     if (theWindow == NULL)
  1242.         return;
  1243.     
  1244.     GetPort(&mySavedPort);
  1245.     MacSetPort(QTFrame_GetPortFromWindowReference(theWindow));
  1246.     
  1247.     // get the window object associated with the specified window
  1248.     myWindowObject = QTFrame_GetWindowObjectFromWindow(theWindow);
  1249.     if (myWindowObject != NULL) {
  1250.         myMC = (**myWindowObject).fController;
  1251.         if (myMC != NULL)
  1252.             MCActivate(myMC, QTFrame_GetWindowFromWindowReference(theWindow), IsActive);
  1253.     }
  1254.     
  1255.     MacSetPort(mySavedPort);
  1256. }
  1257.  
  1258.  
  1259. ///////////////////////////////////////////////////////////////////////////////////////////////////////////
  1260. //
  1261. // Miscellaneous utilities.
  1262. //
  1263. // Use the following functions to play beeps, manipulate menus, and do other miscellaneous things.
  1264. //
  1265. ///////////////////////////////////////////////////////////////////////////////////////////////////////////
  1266.  
  1267. //////////
  1268. //
  1269. // QTFrame_Beep
  1270. // Beep.
  1271. //
  1272. //////////
  1273.  
  1274. void QTFrame_Beep (void)
  1275. {
  1276. #if TARGET_OS_MAC
  1277.     SysBeep(30);
  1278. #endif
  1279. #if TARGET_OS_WIN32
  1280.     MessageBeep(MB_OK);
  1281. #endif
  1282. }
  1283.  
  1284.  
  1285. //////////
  1286. //
  1287. // QTFrame_SetMenuState
  1288. // Set the enabled/disabled state of a menu.
  1289. //
  1290. // On Windows, the theMenuItem parameter must be the (0-based) index in the menu bar of the
  1291. // desired pull-down menu.
  1292. //
  1293. //////////
  1294.  
  1295. void QTFrame_SetMenuState (MenuReference theMenu, UInt16 theMenuItem, short theState)
  1296. {
  1297. #if TARGET_OS_MAC
  1298. #pragma unused(theMenuItem)
  1299.     QTFrame_SetMenuItemState(theMenu, 0, theState);        // menu item == 0 means the entire menu
  1300. #endif
  1301. #if TARGET_OS_WIN32
  1302.     QTFrame_SetMenuItemState(theMenu, theMenuItem, theState | MF_BYPOSITION);
  1303. #endif
  1304. }
  1305.  
  1306.  
  1307. //////////
  1308. //
  1309. // QTFrame_SetMenuItemState
  1310. // Set the enabled/disabled state of a menu item.
  1311. //
  1312. // When running under MacOS 8.5.1, EnableMenuItem and DisableMenuItem seem to do nasty things
  1313. // to the keyboard equivalents associated with a menu; so we'll work around that problem here.
  1314. //
  1315. //////////
  1316.  
  1317. void QTFrame_SetMenuItemState (MenuReference theMenu, UInt16 theMenuItem, short theState)
  1318. {
  1319. #if TARGET_OS_MAC
  1320.     UInt8        myModifiers;
  1321.     
  1322.     // get the existing menu item modifiers
  1323.     GetMenuItemModifiers(theMenu, MENU_ITEM(theMenuItem), &myModifiers);
  1324.     
  1325.     if (theState == kEnableMenuItem)
  1326.         EnableMenuItem(theMenu, MENU_ITEM(theMenuItem));
  1327.     else
  1328.         DisableMenuItem(theMenu, MENU_ITEM(theMenuItem));
  1329.         
  1330.     // restore the previous menu item modifiers
  1331.     SetMenuItemModifiers(theMenu, MENU_ITEM(theMenuItem), myModifiers);
  1332. #endif
  1333. #if TARGET_OS_WIN32
  1334.     EnableMenuItem(theMenu, (UINT)theMenuItem, (UINT)theState);
  1335. #endif
  1336. }
  1337.  
  1338.  
  1339. //////////
  1340. //
  1341. // QTFrame_SetMenuItemLabel
  1342. // Set the label (that is, the text) of a menu item.
  1343. //
  1344. //////////
  1345.  
  1346. void QTFrame_SetMenuItemLabel (MenuReference theMenu, UInt16 theMenuItem, char *theText)
  1347. {
  1348. #if TARGET_OS_MAC
  1349.     Str255        myString;
  1350.     short        mySIndex, myTIndex;
  1351.  
  1352.     // we need to remove the '&' character while converting to a Pascal string    
  1353.     mySIndex = 1;
  1354.     for (myTIndex = 0; myTIndex < strlen(theText); myTIndex++) {
  1355.         if (theText[myTIndex] != '&') {
  1356.             myString[mySIndex] = theText[myTIndex];
  1357.             mySIndex++;
  1358.         }
  1359.     }
  1360.     
  1361.     myString[0] = mySIndex - 1;
  1362.     
  1363.     SetMenuItemText(theMenu, MENU_ITEM(theMenuItem), myString);
  1364. #endif
  1365. #if TARGET_OS_WIN32
  1366.     UINT        myState;
  1367.     
  1368.     // make sure that we preserve the current menu state
  1369.     myState = GetMenuState(theMenu, (UINT)theMenuItem, MF_BYCOMMAND);
  1370.     ModifyMenu(theMenu, (UINT)theMenuItem, MF_BYCOMMAND | MF_STRING | myState, (UINT)theMenuItem, (LPSTR)theText);
  1371. #endif
  1372. }
  1373.  
  1374.  
  1375. //////////
  1376. //
  1377. // QTFrame_SetMenuItemCheck
  1378. // Set the check mark state state of a menu item.
  1379. //
  1380. //////////
  1381.  
  1382. void QTFrame_SetMenuItemCheck (MenuReference theMenu, UInt16 theMenuItem, Boolean theState)
  1383. {
  1384. #if TARGET_OS_MAC
  1385.     MacCheckMenuItem(theMenu, MENU_ITEM(theMenuItem), theState);
  1386. #endif
  1387. #if TARGET_OS_WIN32
  1388.     CheckMenuItem(theMenu, (UINT)theMenuItem, theState ? MF_CHECKED : MF_UNCHECKED);
  1389. #endif
  1390. }
  1391.  
  1392.  
  1393. //////////
  1394. //
  1395. // QTFrame_GetPortFromWindowReference 
  1396. // Return the graphics port associated with a window reference.
  1397. //
  1398. //////////
  1399.  
  1400. GrafPtr QTFrame_GetPortFromWindowReference (WindowReference theWindow)
  1401. {
  1402. #if TARGET_OS_MAC
  1403.     return((GrafPtr)GetWindowPort(theWindow));
  1404. #endif
  1405. #if TARGET_OS_WIN32
  1406.     return(GetNativeWindowPort(theWindow));
  1407. #endif
  1408. }
  1409.  
  1410.  
  1411. //////////
  1412. //
  1413. // QTFrame_GetWindowReferenceFromPort
  1414. // Return the window reference associated with a graphics port.
  1415. //
  1416. //////////
  1417.  
  1418. WindowReference QTFrame_GetWindowReferenceFromPort (GrafPtr thePort)
  1419. {
  1420. #if TARGET_OS_MAC
  1421.     return((WindowReference)GetWindowFromPort((CGrafPtr)thePort));
  1422. #endif
  1423. #if TARGET_OS_WIN32
  1424.     return((WindowReference)GetPortNativeWindow(thePort));
  1425. #endif
  1426. }
  1427.  
  1428.  
  1429. //////////
  1430. //
  1431. // QTFrame_GetWindowFromWindowReference
  1432. // Return the Macintosh window associated with a window reference.
  1433. //
  1434. //////////
  1435.  
  1436. WindowPtr QTFrame_GetWindowFromWindowReference (WindowReference theWindow)
  1437. {
  1438. #if TARGET_OS_MAC
  1439.     return((WindowPtr)theWindow);
  1440. #endif
  1441. #if TARGET_OS_WIN32
  1442.     return((WindowPtr)GetNativeWindowPort(theWindow));
  1443. #endif
  1444. }
  1445.  
  1446.  
  1447. /////////
  1448. //
  1449. // QTFrame_GetWindowWidth
  1450. // Return the width of the specified window.
  1451. //
  1452. //////////
  1453.  
  1454. short QTFrame_GetWindowWidth (WindowReference theWindow)
  1455. {
  1456. #if TARGET_OS_MAC
  1457.     Rect        myRect = {0, 0, 0, 0};
  1458.  
  1459.     if (theWindow != NULL)
  1460.         GetWindowPortBounds(theWindow, &myRect);
  1461. #endif
  1462. #if TARGET_OS_WIN32
  1463.     RECT        myRect = {0L, 0L, 0L, 0L};
  1464.  
  1465.     if (theWindow != NULL)
  1466.         GetWindowRect(theWindow, &myRect);
  1467. #endif
  1468.  
  1469.     return((short)(myRect.right - myRect.left));
  1470. }
  1471.  
  1472.  
  1473. //////////
  1474. //
  1475. // QTFrame_SetWindowTitleFromFSSpec
  1476. // Set the title of the specified window, using the name contained in the specified FSSpec.
  1477. //
  1478. //////////
  1479.  
  1480. void QTFrame_SetWindowTitleFromFSSpec (WindowReference theWindow, FSSpecPtr theFSSpecPtr, Boolean theAddToRecentDocs)
  1481. {
  1482. #if TARGET_OS_MAC
  1483. #pragma unused(theAddToRecentDocs)
  1484.     SetWTitle(theWindow, theFSSpecPtr->name);
  1485. #endif
  1486. #if TARGET_OS_WIN32
  1487.     char    *myTempName;
  1488.     char    myWindName[MAX_PATH];
  1489.  
  1490.     // get the full pathname contained in the FSSpec (which is a Str255)
  1491.     myTempName = QTUtils_ConvertPascalToCString(theFSSpecPtr->name);
  1492.  
  1493.     // get the movie file name from the full pathname
  1494.     QTFrame_GetDisplayName(myTempName, myWindName);
  1495.  
  1496.     // set the window title
  1497.     SetWindowText(theWindow, myWindName);
  1498.     
  1499.     // add this document to the Documents list, if so instructed
  1500.     if (theAddToRecentDocs)
  1501.         SHAddToRecentDocs(SHARD_PATH, myTempName);
  1502.     
  1503.     free(myTempName);
  1504. #endif
  1505. }
  1506.  
  1507.  
  1508. //////////
  1509. //
  1510. // QTFrame_SizeWindowToMovie
  1511. // Set the window size to exactly fit the movie and controller (if visible).
  1512. //
  1513. //////////
  1514.  
  1515. void QTFrame_SizeWindowToMovie (WindowObject theWindowObject)
  1516. {
  1517.     Rect                    myMovieBounds;
  1518.     Movie                    myMovie = NULL;
  1519.     MovieController            myMC = NULL;
  1520.     GraphicsImportComponent    myImporter = NULL;
  1521.  
  1522. #if TARGET_OS_WIN32
  1523.     gWeAreSizingWindow = true;
  1524. #endif
  1525.  
  1526.     if (theWindowObject == NULL)
  1527.         goto bail;
  1528.     
  1529.     myMovie = (**theWindowObject).fMovie;
  1530.     myMC = (**theWindowObject).fController;
  1531.     myImporter = (**theWindowObject).fGraphicsImporter;
  1532.  
  1533.     if (myImporter != NULL) {
  1534.         GraphicsImportGetBoundsRect(myImporter, &myMovieBounds);
  1535.         goto gotBounds;
  1536.     }
  1537.  
  1538.     if (myMovie == NULL)
  1539.         return;
  1540.  
  1541.     GetMovieBox(myMovie, &myMovieBounds);
  1542.  
  1543.     if (myMC != NULL)
  1544.         if (MCGetVisible(myMC))
  1545.             MCGetControllerBoundsRect(myMC, &myMovieBounds);
  1546.     
  1547.     // make sure that the movie has a non-zero width;
  1548.     // a zero height is okay (for example, with a music movie with no controller bar)
  1549.     if (myMovieBounds.right - myMovieBounds.left == 0) {
  1550.         myMovieBounds.left = 0;
  1551.         myMovieBounds.right = QTFrame_GetWindowWidth((**theWindowObject).fWindow);
  1552.     }
  1553.  
  1554. gotBounds:    
  1555.     SizeWindow(QTFrame_GetWindowFromWindowReference((**theWindowObject).fWindow),
  1556.                                             myMovieBounds.right - myMovieBounds.left,
  1557.                                             myMovieBounds.bottom - myMovieBounds.top,
  1558.                                             true);
  1559.  
  1560. bail:                                        
  1561. #if TARGET_OS_WIN32
  1562.     gWeAreSizingWindow = false;
  1563. #endif
  1564.  
  1565.     return;
  1566. }
  1567.  
  1568.  
  1569. ///////////////////////////////////////////////////////////////////////////////////////////////////////////
  1570. //
  1571. // File-opening and -saving utilities.
  1572. //
  1573. // The functions are meant to provide replacements for StandardGetFilePreview and StandardPutFile, which
  1574. // are not supported under Carbon. However, Navigation Services is not (yet, at any rate) supported under
  1575. // Windows, so we still need to call through to the Standard File Package.
  1576. //
  1577. // The Navigation Services portion of this code is based selectively on the file NavigationServicesSupport.c
  1578. // by Yan Arrouye and on the developer documentation "Programming With Navigation Services 1.1". The code that
  1579. // determines which files can be opened by QuickTime is based on code by Sam Bushell in CarbonMovieEditor.c.
  1580. //
  1581. ///////////////////////////////////////////////////////////////////////////////////////////////////////////
  1582.  
  1583. //////////
  1584. //
  1585. // QTFrame_PutFile
  1586. // Save a file under the specified name. Return Boolean values indicating whether the user selected a file
  1587. // and whether the selected file is replacing an existing file.
  1588. //
  1589. //////////
  1590.  
  1591. OSErr QTFrame_PutFile (ConstStr255Param thePrompt, ConstStr255Param theFileName, FSSpecPtr theFSSpecPtr, Boolean *theIsSelected, Boolean *theIsReplacing)
  1592. {
  1593. #if TARGET_OS_WIN32
  1594.     StandardFileReply    myReply;
  1595. #endif
  1596. #if TARGET_OS_MAC
  1597.     NavReplyRecord        myReply;
  1598.     NavDialogOptions    myDialogOptions;
  1599.     NavEventUPP            myEventUPP = NewNavEventProc(QTFrame_HandleNavEvent);
  1600. #endif
  1601.     OSErr                myErr = noErr;
  1602.  
  1603.     if ((theFSSpecPtr == NULL) || (theIsSelected == NULL) || (theIsReplacing == NULL))
  1604.         return(paramErr);
  1605.     
  1606.     // deactivate any frontmost movie window
  1607.     QTFrame_ActivateController(QTFrame_GetFrontMovieWindow(), false);
  1608.  
  1609.     // assume we are not replacing an existing file
  1610.     *theIsReplacing = false;
  1611.     
  1612. #if TARGET_OS_WIN32
  1613.     StandardPutFile(thePrompt, theFileName, &myReply);
  1614.     *theFSSpecPtr = myReply.sfFile;
  1615.     *theIsSelected = myReply.sfGood;
  1616.     if (myReply.sfGood)
  1617.         *theIsReplacing = myReply.sfReplacing;
  1618. #endif
  1619.  
  1620. #if TARGET_OS_MAC
  1621.     // specify the options for the dialog box
  1622.     NavGetDefaultDialogOptions(&myDialogOptions);
  1623.     myDialogOptions.dialogOptionFlags += kNavNoTypePopup;
  1624.     myDialogOptions.dialogOptionFlags += kNavDontAutoTranslate;
  1625.     BlockMoveData(theFileName, myDialogOptions.savedFileName, theFileName[0] + 1);
  1626.     BlockMoveData(gAppName, myDialogOptions.clientName, gAppName[0] + 1);
  1627.     BlockMoveData(thePrompt, myDialogOptions.message, thePrompt[0] + 1);
  1628.     
  1629.     // prompt the user for a file
  1630.     myErr = NavPutFile(NULL, &myReply, &myDialogOptions, myEventUPP, MovieFileType, sigMoviePlayer, NULL);
  1631.     if ((myErr == noErr) && myReply.validRecord) {
  1632.         AEKeyword        myKeyword;
  1633.         DescType        myActualType;
  1634.         Size            myActualSize = 0;
  1635.         
  1636.         // get the FSSpec for the selected file
  1637.         if (theFSSpecPtr != NULL)
  1638.             myErr = AEGetNthPtr(&(myReply.selection), 1, typeFSS, &myKeyword, &myActualType, theFSSpecPtr, sizeof(FSSpec), &myActualSize);
  1639.  
  1640.         NavDisposeReply(&myReply);
  1641.     }
  1642.         
  1643.     *theIsSelected = myReply.validRecord;
  1644.     if (myReply.validRecord)
  1645.         *theIsReplacing = myReply.replacing;
  1646.  
  1647.     DisposeNavEventUPP(myEventUPP);
  1648. #endif
  1649.  
  1650.     return(myErr);
  1651. }
  1652.     
  1653.  
  1654. //////////
  1655. //
  1656. // QTFrame_GetOneFileWithPreview
  1657. // Display the appropriate file-opening dialog box, with an optional QuickTime preview pane. If the user
  1658. // selects a file, return information about it using the theFSSpecPtr parameter.
  1659. //
  1660. // Note that both StandardGetFilePreview and NavGetFile use the function specified by theFilterProc as a
  1661. // file filter. This framework always passes NULL in the theFilterProc parameter. If you use this function
  1662. // in your own code, keep in mind that on Windows the function specifier must be of type FileFilterUPP and 
  1663. // on Macintosh it must be of type NavObjectFilterUPP. (You can use the QTFrame_GetFileFilterUPP to create
  1664. // a function specifier of the appropriate type.) Also keep in mind that Navigation Services expects a file 
  1665. // filter function to return true if a file is to be displayed, while the Standard File Package expects the
  1666. // filter to return false if a file is to be displayed.
  1667. //
  1668. //////////
  1669.  
  1670. OSErr QTFrame_GetOneFileWithPreview (short theNumTypes, QTFrameTypeListPtr theTypeList, FSSpecPtr theFSSpecPtr, void *theFilterProc)
  1671. {
  1672. #if TARGET_OS_WIN32
  1673.     StandardFileReply    myReply;
  1674. #endif
  1675. #if TARGET_OS_MAC
  1676.     NavReplyRecord        myReply;
  1677.     NavDialogOptions    myDialogOptions;
  1678.     NavTypeListHandle    myOpenList = NULL;
  1679.     NavEventUPP            myEventUPP = NewNavEventProc(QTFrame_HandleNavEvent);
  1680. #endif
  1681.     OSErr                myErr = noErr;
  1682.     
  1683.     if (theFSSpecPtr == NULL)
  1684.         return(paramErr);
  1685.     
  1686.     // deactivate any frontmost movie window
  1687.     QTFrame_ActivateController(QTFrame_GetFrontMovieWindow(), false);
  1688.  
  1689. #if TARGET_OS_WIN32
  1690.     // prompt the user for a file
  1691.     StandardGetFilePreview((FileFilterUPP)theFilterProc, theNumTypes, (ConstSFTypeListPtr)theTypeList, &myReply);
  1692.     if (!myReply.sfGood)
  1693.         return(userCanceledErr);
  1694.     
  1695.     // make an FSSpec record
  1696.     myErr = FSMakeFSSpec(myReply.sfFile.vRefNum, myReply.sfFile.parID, myReply.sfFile.name, theFSSpecPtr);
  1697. #endif
  1698.  
  1699. #if TARGET_OS_MAC
  1700.     // specify the options for the dialog box
  1701.     NavGetDefaultDialogOptions(&myDialogOptions);
  1702.     myDialogOptions.dialogOptionFlags -= kNavNoTypePopup;
  1703.     myDialogOptions.dialogOptionFlags -= kNavAllowMultipleFiles;
  1704.     BlockMoveData(gAppName, myDialogOptions.clientName, gAppName[0] + 1);
  1705.     
  1706.     // create a handle to an 'open' resource
  1707.     myOpenList = (NavTypeListHandle)QTFrame_CreateOpenHandle(kApplicationSignature, theNumTypes, theTypeList);
  1708.     if (myOpenList != NULL)
  1709.         HLock((Handle)myOpenList);
  1710.     
  1711.     // prompt the user for a file
  1712.     myErr = NavGetFile(NULL, &myReply, &myDialogOptions, myEventUPP, NULL, (NavObjectFilterUPP)theFilterProc, myOpenList, NULL);
  1713.     if ((myErr == noErr) && myReply.validRecord) {
  1714.         AEKeyword        myKeyword;
  1715.         DescType        myActualType;
  1716.         Size            myActualSize = 0;
  1717.         
  1718.         // get the FSSpec for the selected file
  1719.         if (theFSSpecPtr != NULL)
  1720.             myErr = AEGetNthPtr(&(myReply.selection), 1, typeFSS, &myKeyword, &myActualType, theFSSpecPtr, sizeof(FSSpec), &myActualSize);
  1721.  
  1722.         NavDisposeReply(&myReply);
  1723.     }
  1724.     
  1725.     if (myOpenList != NULL) {
  1726.         HUnlock((Handle)myOpenList);
  1727.         DisposeHandle((Handle)myOpenList);
  1728.     }
  1729.     
  1730.     DisposeNavEventUPP(myEventUPP);
  1731. #endif
  1732.  
  1733.     return(myErr);
  1734. }
  1735.  
  1736.  
  1737. //////////
  1738. //
  1739. // QTFrame_HandleNavEvent
  1740. // A callback procedure that handles events while a Navigation Service dialog box is displayed.
  1741. //
  1742. //////////
  1743.  
  1744. PASCAL_RTN void QTFrame_HandleNavEvent (NavEventCallbackMessage theCallBackSelector, NavCBRecPtr theCallBackParms, void *theCallBackUD)
  1745. {
  1746. #pragma unused(theCallBackUD)
  1747.     WindowReference        myWindow = NULL;    
  1748.     
  1749.     if (theCallBackSelector == kNavCBEvent) {
  1750.         switch (theCallBackParms->eventData.eventDataParms.event->what) {
  1751.             case updateEvt:
  1752. #if TARGET_OS_MAC
  1753.                 QTFrame_HandleEvent(theCallBackParms->eventData.eventDataParms.event);
  1754. #endif
  1755.                 break;
  1756.             case nullEvent:
  1757.                 QTFrame_IdleMovieWindows();
  1758.                 break;
  1759.         }
  1760.     }
  1761. }
  1762.  
  1763.  
  1764. //////////
  1765. //
  1766. // QTFrame_CreateOpenHandle
  1767. // Return a handle to a dynamically-created 'open' resource.
  1768. //
  1769. //////////
  1770.  
  1771. Handle QTFrame_CreateOpenHandle (OSType theApplicationSignature, short theNumTypes, QTFrameTypeListPtr theTypeList)
  1772. {
  1773.     Handle            myHandle = NULL;
  1774.     
  1775.     if (theTypeList == NULL)
  1776.         return(myHandle);
  1777.     
  1778.     if (theNumTypes > 0) {
  1779.         myHandle = NewHandle(sizeof(NavTypeList) + (theNumTypes * sizeof(OSType)));
  1780.         if (myHandle != NULL) {
  1781.             NavTypeListHandle     myOpenResHandle    = (NavTypeListHandle)myHandle;
  1782.             
  1783.             (*myOpenResHandle)->componentSignature = theApplicationSignature;
  1784.             (*myOpenResHandle)->osTypeCount = theNumTypes;
  1785.             BlockMoveData(theTypeList, (*myOpenResHandle)->osType, theNumTypes * sizeof(OSType));
  1786.         }
  1787.     }
  1788.     
  1789.     return(myHandle);
  1790. }
  1791.  
  1792.  
  1793. //////////
  1794. //
  1795. // QTFrame_GetFileFilterUPP
  1796. // Return a UPP for the specified file-selection filter function.
  1797. //
  1798. // The caller is responsible for disposing of the UPP returned by this function (by calling DisposeRoutineDescriptor).
  1799. //
  1800. //////////
  1801.  
  1802. QTFrameFileFilterUPP QTFrame_GetFileFilterUPP (ProcPtr theFileFilterProc)
  1803. {
  1804. #if TARGET_OS_MAC
  1805.     return(NewNavObjectFilterUPP((NavObjectFilterProcPtr)theFileFilterProc));
  1806. #endif
  1807. #if TARGET_OS_WIN32
  1808.     return(NewFileFilterProc(theFileFilterProc));
  1809. #endif
  1810. }
  1811.  
  1812.  
  1813. //////////
  1814. //
  1815. // QTFrame_FilterFiles
  1816. // Filter files for a file-opening dialog box.
  1817. //
  1818. // The default behavior here is to accept all files that can be opened by QuickTime, whether directly
  1819. // or using a movie importer or a graphics importer.
  1820. //
  1821. //////////
  1822.  
  1823. #if TARGET_OS_MAC
  1824. PASCAL_RTN Boolean QTFrame_FilterFiles (AEDesc *theItem, void *theInfo, void *theCallBackUD, NavFilterModes theFilterMode)
  1825. {
  1826. #pragma unused(theCallBackUD, theFilterMode)
  1827.     NavFileOrFolderInfo        *myInfo = (NavFileOrFolderInfo *)theInfo;
  1828.     
  1829.     if (gValidFileTypes == NULL)
  1830.         QTFrame_BuildFileTypeList();
  1831.  
  1832.     if (theItem->descriptorType == typeFSS) {
  1833.         if (!myInfo->isFolder) {
  1834.             OSType            myType = myInfo->fileAndFolder.fileInfo.finderInfo.fdType;
  1835.             short            myCount;
  1836.             short            myIndex;
  1837.             
  1838.             // see whether the file type is in the list of file types that our application can open 
  1839.             myCount = GetPtrSize((Ptr)gValidFileTypes) / sizeof(OSType);
  1840.             for (myIndex = 0; myIndex < myCount; myIndex++)
  1841.                 if (myType == gValidFileTypes[myIndex])
  1842.                     return(true);
  1843.  
  1844.             // if we got to here, it's a file we cannot open
  1845.             return(false);        
  1846.         }
  1847.     }
  1848.     
  1849.     // if we got to here, it's a folder or non-HFS object
  1850.     return(true);
  1851. }
  1852. #endif
  1853. #if TARGET_OS_WIN32
  1854. PASCAL_RTN Boolean QTFrame_FilterFiles (CInfoPBPtr thePBPtr)
  1855. {
  1856. #pragma unused(thePBPtr)
  1857.     return(false);
  1858. }
  1859. #endif
  1860.  
  1861.  
  1862. //////////
  1863. //
  1864. // QTFrame_BuildFileTypeList
  1865. // Build a list of file types that QuickTime can open.
  1866. //
  1867. //////////
  1868.  
  1869. OSErr QTFrame_BuildFileTypeList (void)
  1870. {
  1871.     long        myIndex = 0;
  1872.     OSErr        myErr = noErr;
  1873.  
  1874.     // if we've already built the list, just return
  1875.     if (gValidFileTypes != NULL)
  1876.         return(myErr);
  1877.     
  1878.     // allocate a block of memory to hold a preset number of file types; we'll resize this block
  1879.     // while building the list if we need more room; we always resize it after building the list,
  1880.     // to truncate it to the exact size required
  1881.     gValidFileTypes = (OSType *)NewPtrClear(sizeof(OSType) * kDefaultFileTypeCount);
  1882.     if (gValidFileTypes == NULL)
  1883.         return(memFullErr);
  1884.     
  1885.     // we can open any files of type kQTFileTypeMovie
  1886.     gValidFileTypes[myIndex++] = kQTFileTypeMovie;
  1887.     
  1888.     // we can open any files for which QuickTime supplies a movie importer component
  1889.     QTFrame_AddComponentFileTypes(MovieImportType, &myIndex);
  1890.     
  1891.     // we can open any files for which QuickTime supplies a graphics importer component
  1892.     QTFrame_AddComponentFileTypes(GraphicsImporterComponentType, &myIndex);
  1893.  
  1894.     // resize the pointer to hold the exact number of valid file types
  1895.     SetPtrSize((Ptr)gValidFileTypes, myIndex * sizeof(OSType));
  1896.     myErr = MemError();
  1897.     
  1898.     return(myErr);
  1899. }
  1900.  
  1901.  
  1902. //////////
  1903. //
  1904. // QTFrame_AddComponentFileTypes
  1905. // Add all subtypes of the specified component type to the global list of file types.
  1906. //
  1907. //////////
  1908.  
  1909. static void QTFrame_AddComponentFileTypes (OSType theComponentType, long *theNextIndex)
  1910. {
  1911.     ComponentDescription        myFindCompDesc = {0, 0, 0, 0, 0};
  1912.     ComponentDescription        myInfoCompDesc = {0, 0, 0, 0, 0};
  1913.     Component                    myComponent = NULL;
  1914.  
  1915.     myFindCompDesc.componentType = theComponentType;
  1916.     myFindCompDesc.componentFlags = 0;
  1917.     myFindCompDesc.componentFlagsMask = movieImportSubTypeIsFileExtension;
  1918.  
  1919.     myComponent = FindNextComponent(myComponent, &myFindCompDesc);
  1920.     while (myComponent != NULL) {
  1921.         GetComponentInfo(myComponent, &myInfoCompDesc, NULL, NULL, NULL);
  1922.         gValidFileTypes[*theNextIndex] = myInfoCompDesc.componentSubType;
  1923.         *theNextIndex += 1;
  1924.         
  1925.         // resize the block of file types, if we are about to reach the limit
  1926.         if (*theNextIndex == GetPtrSize((Ptr)gValidFileTypes) / (long)sizeof(OSType)) {
  1927.             SetPtrSize((Ptr)gValidFileTypes, GetPtrSize((Ptr)gValidFileTypes) + (kDefaultFileTypeCount * sizeof(OSType)));
  1928.             if (MemError() != noErr)
  1929.                 return;
  1930.         }
  1931.         
  1932.         myComponent = FindNextComponent(myComponent, &myFindCompDesc);
  1933.     }
  1934. }
  1935.  
  1936.  
  1937. #if TARGET_OS_WIN32
  1938. //////////
  1939. //
  1940. // QTFrame_ConvertMacToWinRect
  1941. // Convert a Macintosh Rect structure into a Windows RECT structure.
  1942. //
  1943. //////////
  1944.  
  1945. void QTFrame_ConvertMacToWinRect (Rect *theMacRect, RECT *theWinRect)
  1946. {
  1947.     theWinRect->top = (long)theMacRect->top;
  1948.     theWinRect->left = (long)theMacRect->left;
  1949.     theWinRect->bottom = (long)theMacRect->bottom;
  1950.     theWinRect->right = (long)theMacRect->right;
  1951. }
  1952.  
  1953.  
  1954. //////////
  1955. //
  1956. // QTFrame_ConvertWinToMacRect
  1957. // Convert a Windows RECT structure into a Macintosh Rect structure.
  1958. //
  1959. //////////
  1960.  
  1961. void QTFrame_ConvertWinToMacRect (RECT *theWinRect, Rect *theMacRect)
  1962. {
  1963.     theMacRect->top = (short)theWinRect->top;
  1964.     theMacRect->left = (short)theWinRect->left;
  1965.     theMacRect->bottom = (short)theWinRect->bottom;
  1966.     theMacRect->right = (short)theWinRect->right;
  1967. }
  1968. #endif
  1969.